/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.javanile.uxml;

import java.util.Hashtable;
import java.util.Enumeration;
/**
 *
 * @author cicciodarkast
 */
public class uXmlDocument {
	private Hashtable 	ns;
	private String 		data;
	private int         index;
	private int			caret;

	public uXmlDocument() {
		ns = new Hashtable();
		data = new String();
        index = 0;
		caret = 0;
	}

	public void set(String x) {
		data = x;
	}
	
	public boolean next(String tag) {
		for(int i=caret;i<ns.size();i++) {

			int[] n = (int[])ns.get(new Integer(i));
			String ntag = data.substring(n[0]+1, n[2]).trim();
			//System.out.println(" - "+ntag+" "+tag+" "+i+" "+caret);
			
			if (ntag.equals(tag)) {
				caret = i+1;
				return true;
			}
			
		}
		return false;
	}
	public String content() {
		int[] n = (int[])ns.get(new Integer(caret-1));
		//System.out.println(n);
		String ncontent = data.substring(n[2]+1, n[3]);
		return ncontent;
	}
	public void add(uXmlNode n) {
            ns.put(new Integer(index),n.n);
            index++;
	}
	public void dump() {
            Enumeration en = ns.elements();
            while(en.hasMoreElements()) {
                int[] node = (int[])en.nextElement();
                System.out.println(node);
                for(int i=0;i<node.length;i++) {
                    System.out.print(node[i]+" ");
                }
				System.out.print("\n");
            }
	}
}
